package com.way.common.core.config;

import com.way.common.core.domain.R;
import com.way.common.core.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author lewis
 * @Date 2024-12-07
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<String> exception(Exception e) {
        log.error("全局异常信息 ex={}", e.getMessage(), e);
        return R.fail(e.getLocalizedMessage());
    }

    @ExceptionHandler(GlobalException.class)
    public R<String> globalException(GlobalException e) {
        log.error("Global异常 ex={}", e.getMessage(), e);
        return R.fail(e.getLocalizedMessage());
    }

}
